using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spikes : MonoBehaviour, IInteractable
{
    public float damage;
    public LayerMask layerMask;

    private Animator animator;
    private BoxCollider2D testCollider2D;
    private CapsuleCollider2D hitCollider2D;
    private void Awake()
    {
        animator = GetComponent<Animator>();
        testCollider2D = GetComponent<BoxCollider2D>();
        hitCollider2D = GetComponent<CapsuleCollider2D>();
    }
    private void Start()
    {
        ChangeBeforeInteracte();
    }
    private void Update()
    {
        
    }
    public void ChangeBeforeInteracte()
    {
        hitCollider2D.enabled = false;
        testCollider2D.enabled = true;
    }

    public void Interacte(GameObject trigger)
    {
        animator.SetTrigger("isOpen");
    }
    public void ChangeAfterInteracte()
    {
        hitCollider2D.enabled = true;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(testCollider2D.IsTouchingLayers(layerMask))
        {
            testCollider2D.enabled = false;
            Interacte(null);
            
        }
        else if(hitCollider2D.IsTouchingLayers(layerMask))
        {
            collision.GetComponent<HealthControllerBase>().Hit(damage);
        }
        
    }

}
